<div navbar ng-init="currentItem='file'"></div>
<div ng-show="!loaded">
    <div loading></div>
</div>

<div id="main" ng-show="loaded" style="display:none">
    <div class="module-header">
        <h3>文件管理</h3>
    </div>

    <div ng-init="load()" id="list" class="file-list">
        <div class="row padding-bottom">
            <div class="col-md-8 col-sm-9 col-xs-9">
                <form onsubmit="return false;" ng-submit="listdir()">
                    <div class="input-group input-group-sm">
                        <span class="input-group-addon">当前目录</span>
                        <input class="form-control" type="text" ng-model="path">
                        <div class="input-group-btn">
                            <button class="btn btn-default btn-sm" type="submit" title="刷新"><span class="glyphicon glyphicon-refresh"></span>
                            <button class="btn btn-default btn-sm" type="submit" title="进入"><span class="glyphicon glyphicon-menu-right"></span></button>
                        </div>
                    </div>
                </form>
            </div>
            <div class="col-md-4 col-sm-3 col-xs-3">
                <a class="btn btn-default btn-sm pull-right" href="#/file/trash">
                    <span class="glyphicon glyphicon-trash"></span> 回收站
                </a>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <ul class="breadcrumb">
                    <li>路径导航：</li>
                    <li><a ng-click="listdir('/')">根目录</a></li>
                    <li ng-repeat="pathinfo in pathinfos" ng-show="pathinfos.length>0">
                        <a ng-click="listdir(pathinfo.path)">{{pathinfo.name}}</a>
                    </li>
                </ul>
            </div>
        </div>
        <div class="row">
            <div class="col-md-9 pull-left">
                <div class="btn-group btn-group-sm">
                    <button class="btn btn-default" ng-disabled="fileloading" ng-click="upandlist()"><i class="glyphicon glyphicon-level-up"></i> 返回上级</button>
                    <button class="btn btn-default" ng-disabled="fileloading" ng-click="newfolder()"><i class="glyphicon glyphicon-plus-sign"></i> 新建文件夹</button>
                    <button class="btn btn-default" ng-disabled="fileloading" ng-click="newfile()"><i class="glyphicon glyphicon-plus-sign"></i> 新建文件</button>
                    <button class="btn btn-default" ng-disabled="fileloading" ng-click="upload()"><i class="glyphicon glyphicon-upload"></i> 上传文件</button>
                    <button class="btn btn-default" ng-disabled="fileloading" ng-click="download()"><i class="glyphicon glyphicon-download"></i> 下载资源</button>
                    <button class="btn btn-default" ng-click="paste()" ng-disabled="clipboard.count==0||fileloading"><i class="glyphicon glyphicon-paste"></i> 粘贴/链接</button>
                </div>
            </div>
            <div class="col-md-3">
                <button class="btn btn-default btn-sm pull-right" data-toggle="button" ng-click="togglehidden()"><i class="glyphicon glyphicon-eye-open"></i> 显示隐藏文件和目录</button>
            </div>
        </div>

        <div style="margin-top:30px;margin-bottom: 30px;" ng-show="fileloading">
            <div waiting ng-init="waitingText='正在加载文件列表，请稍候...'"></div>
        </div>

        <div ng-show="!fileloading">
            <table class="table table-hover table-bordered table-condensed" style="margin-top:10px;">
                <thead>
                    <tr>
                        <th style="width:10px"><input type="checkbox" ng-model="selectall"></th>
                        <th>名称</th>
                        <th style="width:50px">大小</th>
                        <th style="width:50px">用户</th>
                        <th style="width:50px">组</th>
                        <th style="width:40px">权限</th>
                        <th style="width:150px">修改时间</th>
                        <th style="width:140px">操作</th>
                        <th style="width:40px">压缩</th>
                        <th style="width:70px">其它</th>
                    </tr>
                </thead>
                <tbody>
                    <tr ng-show="items.length==0">
                        <td colspan="10">当前目录是空的。</td>
                    </tr>
                    <tr ng-class="'warning'|iftrue:clipboard.srcpath==curpath&&clipboard.items[item.name]" ng-repeat="item in items">
                        <td><input type="checkbox" ng-model="selects[item.name]"></td>
                        <td>
                            <i class="glyphicon glyphicon-folder-open" title="文件夹" ng-show="item.isdir"></i>
                            <i class="glyphicon glyphicon-file" title="文件" ng-show="item.isreg"></i>
                            <i class="glyphicon glyphicon-link" title="链接" ng-show="item.islnk&&(item.link_isdir||item.link_isreg)"></i>
                            <i class="glyphicon glyphicon-ban-circle" title="未知" ng-show="!item.isdir&&!item.isreg&&(!item.islnk||(item.islnk&&!item.link_isdir&&!item.link_isreg))"></i>
                            &nbsp;
                            <a class="black" ng-click="listdir(curpath+'/'+item.name)" ng-show="item.isdir||(item.islnk&&item.link_isdir)">{{item.name}}</a>
                            <a class="black" ng-click="editfile(item.name)" ng-show="item.isreg||(item.islnk&&!item.link_isdir)">{{item.name}}</a>
                            <span class="text-info" ng-show="item.islnk&&!item.link_broken"><br />-> {{item.linkto}}</span>
                            <span class="text-error" ng-show="item.islnk&&item.link_broken">(原文件已丢失)<br />-> {{item.linkto}}</span>
                        </td>
                        <td class="text-right" style="padding-right:15px">{{item.size}}</td>
                        <td><a class="black" ng-click="chownconfirm(item.name, item.uname, item.gname, item.isdir)">{{item.uname|iftrue:item.uname!=''}}{{item.uid|iftrue:item.uname==''}}</a></td>
                        <td><a class="black" ng-click="chownconfirm(item.name, item.uname, item.gname, item.isdir)">{{item.gname|iftrue:item.gname!=''}}{{item.gid|iftrue:item.gname==''}}</a></td>
                        <td><a class="black" ng-click="chmodconfirm(item.name, item.perms, item.isdir)">{{item.perms}}</a></td>
                        <td>{{item.mtime}}</td>
                        <td>
                            <div class="btn-group">
                                <button class="btn btn-default btn-xs" ng-click="rename(item.name)" title="改名">改</button>
                                <button class="btn btn-default btn-xs" ng-class="'active'|iftrue:clipboard.srcpath==curpath&&clipboard.items[item.name]=='copy'" ng-click="togglecopy(item.name)" title="复制">复</button>
                                <button class="btn btn-default btn-xs" ng-class="'active'|iftrue:clipboard.srcpath==curpath&&clipboard.items[item.name]=='cut'" ng-click="togglecut(item.name)" title="剪切">剪</button>
                                <button class="btn btn-default btn-xs" ng-class="'active'|iftrue:clipboard.srcpath==curpath&&clipboard.items[item.name]=='link'" ng-click="togglelink(item.name)" title="链接">链</button>
                                <button class="btn btn-default btn-xs" ng-click="move2trash(item.name)" title="删除">删</button>
                            </div>
                        </td>
                        <td>
                            <button class="btn btn-default btn-xs" ng-click="decompress(item.name)" ng-show="true | ifmatch:[item.name, '.*\.(zip|gz|tgz|bz2)']" title="解压">解压</button>
                            <button class="btn btn-default btn-xs" ng-click="compressconfirm(item.name, item.isreg)" ng-show="true | ifnotmatch:[item.name, '.*\.(zip|gz|tgz|bz2)']" title="压缩">压缩</button>
                        </td>
                        <td>
                            <div class="btn-group" ng-show="item.isdir||(item.islnk&&item.link_isdir)">
                                <button class="btn btn-default btn-xs" ng-disabled="true" title="设置自动同步（即将推出）"><i class="glyphicon glyphicon-repeat"></i></button>
                                <button class="btn btn-default btn-xs" ng-disabled="true" title="设置自动备份（即将推出）"><i class="glyphicon glyphicon-share-alt"></i></button>
                            </div>
                            <a class="btn btn-default btn-xs" href="/download/{{item.download}}" ng-show="item.isreg||(item.islnk&&item.link_isreg)" title="下载"><i class="glyphicon glyphicon-download-alt"></i></button>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <div style="margin-top:5px;height:30px;">
            <div class="pull-left">
                <span>批量操作：</span>
                <button class="btn btn-default btn-sm" ng-disabled="fileloading" ng-click="multicopy()"><i class="glyphicon glyphicon-duplicate"></i> 复制</button>
                <button class="btn btn-default btn-sm" ng-disabled="fileloading" ng-click="multicut()"><i class="glyphicon glyphicon-scissors"></i> 剪切</button>
                <button class="btn btn-default btn-sm" ng-disabled="fileloading" ng-click="multidel()"><i class="glyphicon glyphicon-remove"></i> 删除</button>
                <button class="btn btn-default btn-sm" ng-disabled="fileloading" ng-click="tarconfirm()"><i class="glyphicon glyphicon-compressed"></i> 打包压缩</button>
                <button class="btn btn-default btn-sm" ng-disabled="fileloading" ng-click="chownconfirm()"><i class="glyphicon glyphicon-user"></i> 用户和组</button>
                <button class="btn btn-default btn-sm" ng-disabled="fileloading" ng-click="chmodconfirm()"><i class="glyphicon glyphicon-lock"></i> 修改权限</button>
            </div>
            <div class="pull-right">
            </div>
        </div>
    </div>

    <div style="display:none" id="edit">
        <h4>正在编辑：{{filepath}}</h4>
        <div style="margin:15px 0;height:30px;">
            <div class="pull-left">
                <button class="btn btn-default btn-sm" ng-click="return2list()">
                    <span class="glyphicon glyphicon-chevron-left"></span> 返回文件列表
                </button>
            </div>
            <div class="pull-right">
                字符编码：<select class="input-sm" ng-model="filecharset" style="width:120px;margin-bottom:0;margin-right:10px">
                    <option value="utf-8">UTF-8</option>
                    <option value="gb2312">GB2312</option>
                    <option value="gbk">GBK</option>
                    <option value="gb18030">GB18030</option>
                    <option value="big5">BIG5</option>
                    <option value="euc-jp">EUC-JP</option>
                    <option value="euc-kr">EUC-KR</option>
                    <option value="iso-8859-2">ISO-8859-2</option>
                    <option value="shift_jis">Shift_JIS</option>
                </select>
                <button class="btn btn-primary btn-sm" ng-click="savefile()"><span class="glyphicon glyphicon-ok"></span> 保存修改</button>
                <button class="btn btn-default btn-sm" ng-click="canceledit()"><span class="glyphicon glyphicon-remove"></span> 放弃修改</button>
            </div>
        </div>
        <div id="editor"></div>
        <div style="margin:15px 0;height:30px;">
            <div class="pull-left">
                <button class="btn btn-default btn-sm" ng-click="return2list()">
                    <span class="glyphicon glyphicon-chevron-left"></span> 返回文件列表
                </button>
            </div>
            <div class="pull-right">
                字符编码：<select class="input-sm" ng-model="filecharset" style="width:120px;margin-bottom:0;margin-right:10px">
                    <option value="utf-8">UTF-8</option>
                    <option value="gb2312">GB2312</option>
                    <option value="gbk">GBK</option>
                    <option value="gb18030">GB18030</option>
                    <option value="big5">BIG5</option>
                    <option value="euc-jp">EUC-JP</option>
                    <option value="euc-kr">EUC-KR</option>
                    <option value="iso-8859-2">ISO-8859-2</option>
                    <option value="shift_jis">Shift_JIS</option>
                </select>
                <button class="btn btn-primary btn-sm" ng-click="savefile()"><span class="glyphicon glyphicon-ok"></span> 保存修改</button>
                <button class="btn btn-default btn-sm" ng-click="canceledit()"><span class="glyphicon glyphicon-remove"></span> 放弃修改</button>
            </div>
        </div>
    </div>
</div>

<div id="overwriteconfirm" class="modal fade">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title">操作确认</h3>
            </div>
            <div class="modal-body">
                <p>{{overwrite_filename}} 已存在，如何处理？</p>
                <div class="form-group">
                <div class="radio">
                    <label>
                        <input type="radio" ng-model="overwrite_option" value="overwrite">覆盖该文件或目录
                    </label>
                </div>
                </div>
                <div class="form-group">
                <div class="radio">
                    <label>
                    <input type="radio" ng-model="overwrite_option" value="rename">重命名为<br />
                    <input class="form-control" style="margin-top:10px" type="text" ng-model="overwrite_newname" ng-disabled="overwrite_option=='overwrite'">
                    </label>
                </div>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true" ng-click="cancel()">取消</button>
                <button class="btn btn-primary" onclick="$('#overwriteconfirm').modal('hide')" ng-click="overwrite()">确定</button>
            </div>
        </div>
    </div>
</div>

<div id="newname" class="modal fade" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title">{{newname_title}}</h3>
            </div>
            <div class="modal-body">
                <div class="input-group">
                    <span class="input-group-addon">{{newname_label}}</span>
                    <input class="form-control" type="text" ng-model="newname_name">
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">取消</button>
                <button class="btn btn-primary" onclick="$('#newname').modal('hide')" ng-click="newname()">确定</button>
            </div>
        </div>
    </div>
</div>

<div id="upload" class="modal fade">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title">上传文件到当前目录</h3>
            </div>
            <div class="modal-body">
                <h5>请选择您要上传的文件：</h5>
                <div ng-include src="'/xsrf'"></div>
                <form id="uploadform" target="uploadframe" action="/fileupload" enctype="multipart/form-data" method="post" onsubmit="$('#_xsrf').val(getCookie('XSRF-TOKEN'))">
                    <input type="hidden" name="_xsrf" value="" id="_xsrf">
                    <input type="hidden" name="path" value="{{curpath}}">
                    <div class="input-group">
                        <input name="ufile" type="file" class="form-control">
                        <div class="input-group-btn">
                            <button class="btn btn-default" ng-click="doupload()">开始上传</button>
                        </div>
                    </div>
                </form>
                <iframe frameborder="0" name="uploadframe" width="100%" height="50"></iframe>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true" ng-click="listdir()">关闭</button>
            </div>
        </div>
    </div>
</div>

<div id="download" class="modal fade">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title">下载资源到当前目录</h3>
            </div>
            <div class="modal-body">
                <div style="margin:10px 20px">
                <h5>请在下框中输入资源的URL（一次只能下载一个）：</h5>
                <textarea class="form-control" rows="4" ng-model="downloadurl"></textarea>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">取消</button>
                <button class="btn btn-primary" onclick="$('#download').modal('hide')" ng-click="dodownload()">开始下载</button>
            </div>
        </div>
    </div>
</div>

<div id="compressconfirm" class="modal fade">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title">压缩 {{compress_name}}</h3>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" onsubmit="return false">
                    <div class="form-group">
                        <div class="col-sm-3 control-label">
                            <label class="control-label">压缩格式：</label>
                        </div>
                        <div class="col-sm-3 control-label">
                            <select class="form-control" ng-model="compress_type">
                            <option value=".gz" ng-show="compress_isreg">.gz</option>
                            <option value=".tar.gz">.tar.gz</option>
                            <option value=".tar.bz2">.tar.bz2</option>
                            <option value=".zip">.zip</option>
                            <option value=".tgz">.tgz</option>
                            </select>
                        </div>
                        </div>
                        <div class="form-group" ng-show="compress_type!='.gz'">
                        <div class="col-sm-3 control-label">
                            <label class="control-label">压缩包文件名：</label>
                        </div>
                        <div class="col-sm-6 control-label">
                            <div class="input-group">
                            <input class="form-control" type="text" ng-model="compress_zipname">
                            <span class="input-group-addon">{{compress_type}}</span>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">取消</button>
                <button class="btn btn-primary" onclick="$('#compressconfirm').modal('hide')" ng-click="tar()" ng-show="compress_names.length>0">确定</button>
                <button class="btn btn-primary" onclick="$('#compressconfirm').modal('hide')" ng-click="compress()" ng-show="compress_names.length==0">确定</button>
            </div>
        </div>
    </div>
</div>

<div id="selector" class="modal fade">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title">{{selector_title}}</h3>
            </div>
            <div class="modal-body">
                <div selector></div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">取消</button>
            </div>
        </div>
    </div>
</div>

<div id="chownconfirm" class="modal fade">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title">修改用户和用户组</h3>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" onsubmit="return false">
                    <div class="form-group">
                    <div class="col-sm-3 control-label">
                        <label class="control-label">用户：</label>
                    </div>
                    <div class="col-sm-9 control-label">
                        <select class="form-control" style="width:150px" ng-model="chown_user" ng-options="user for user in users"></select>
                    </div>
                    </div>
                    <div class="form-group">
                    <div class="col-sm-3 control-label">
                        <label class="control-label">用户组：</label>
                    </div>
                    <div class="col-sm-9 control-label">
                        <select class="form-control" style="width:150px" ng-model="chown_group" ng-options="group for group in groups"></select>
                    </div>
                    </div>
                    <div class="form-group" ng-show="chown_hasdir">
                    <div class="col-sm-3 control-label">
                        <label class="control-label">递归修改：</label>
                    </div>
                    <div class="col-sm-9">
                        <div class="checkbox">
                        <label class="control-label">
                            <input type="checkbox" ng-model="chown_recursively"> 同时修改所有子目录中的项目
                        </label>
                        </div>
                    </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">取消</button>
                <button class="btn btn-primary" onclick="$('#chownconfirm').modal('hide')" ng-click="chown()">确定</button>
            </div>
        </div>
    </div>
</div>

<div id="chmodconfirm" class="modal fade">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title">修改权限</h3>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" onsubmit="return false">
                    <div class="form-group">
                        <div class="col-sm-3 control-label">
                            <label class="control-label">所有者权限：</label>
                        </div>
                        <div class="col-sm-9">
                            <div class="checkbox">
                                <label class="checkbox-inline"><input type="checkbox" ng-model="chmod_permbits[0][0]"> 读取</label>
                                <label class="checkbox-inline"><input type="checkbox" ng-model="chmod_permbits[0][1]"> 写入</label>
                                <label class="checkbox-inline"><input type="checkbox" ng-model="chmod_permbits[0][2]"> 可执行</label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-3 control-label">
                            <label class="control-label">所属用户组权限：</label>
                        </div>
                        <div class="col-sm-9">
                            <div class="checkbox">
                                <label class="checkbox-inline"><input type="checkbox" ng-model="chmod_permbits[1][0]"> 读取</label>
                                <label class="checkbox-inline"><input type="checkbox" ng-model="chmod_permbits[1][1]"> 写入</label>
                                <label class="checkbox-inline"><input type="checkbox" ng-model="chmod_permbits[1][2]"> 可执行</label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-3 control-label">
                        <label class="control-label">其他用户组权限：</label>
                        </div>
                        <div class="col-sm-9">
                            <div class="checkbox">
                                <label class="checkbox-inline"><input type="checkbox" ng-model="chmod_permbits[2][0]"> 读取</label>
                                <label class="checkbox-inline"><input type="checkbox" ng-model="chmod_permbits[2][1]"> 写入</label>
                                <label class="checkbox-inline"><input type="checkbox" ng-model="chmod_permbits[2][2]"> 可执行</label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group" ng-show="chmod_hasdir">
                        <div class="col-sm-3 control-label">
                            <label class="control-label">递归修改：</label>
                        </div>
                        <div class="col-sm-9">
                            <div class="checkbox">
                                <label class="control-label"><input type="checkbox" ng-model="chmod_recursively"> 同时修改所有子目录中的项目</label>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">取消</button>
                <button class="btn btn-primary" onclick="$('#chmodconfirm').modal('hide')" ng-click="chmod()">确定</button>
            </div>
        </div>
    </div>
</div>

<div id="confirm" class="modal fade">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title">{{confirm_title}}</h3>
            </div>
            <div class="modal-body" ng-bind-html-unsafe="confirm_body">
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true" ng-click="cancel()">取消</button>
                <button class="btn btn-primary" onclick="$('#confirm').modal('hide')" ng-click="confirm()">确定</button>
            </div>
        </div>
    </div>
</div>